/*==========================================================================*/
/*                             nms_gr303.h                                  */
/*                                                                          */
/*   This is the include file for GR-303 library structures,                */
/*                      commands, error codes.                              */
/*                                                                          */
/*                                                                          */
/* Copyright (c)2001 NMS Communications. All rights reserved.               */
/*==========================================================================*/

#ifndef _NMSGR303LIB_H_
#define _NMSGR303LIB_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "nmstypes.h"

#define NMS_GR303_INTERFACE_GROUPS              256
#define NMS_GR303_CHANNEL_LOCATIONS             4
#define NMS_GR303_DS1_LOCATIONS                 28
#define NMS_GR303_RX_BUFFER_SIZE                260
#define NMS_GR303_TX_BUFFER_SIZE                260
#define NMS_GR303_MIN_TRACE_BUF_SIZE            350

typedef DWORD       NMS_GR303_INTERFACE_ID_T;
typedef DWORD       NMS_GR303_CHANNEL_EVENT_T;
typedef DWORD       NMS_GR303_DS1_STATUSMASK_T;
    
typedef enum _NMS_GR303_BOARD_T
{
    NMS_BOARD_FAMILY_CG               = 0x01   /* Falcon Generation Family     */
} NMS_GR303_BOARD_FAMILY_T;

typedef union _NMS_GR303_DS1_LOCATION_T
{
    struct {
        DWORD boardNb;
        DWORD trunkNb;      
    } CG;
} NMS_GR303_DS1_LOCATION_T;

typedef union _NMS_GR303_CHANNEL_LOCATION_T
{
    struct {
        DWORD  boardNb;
        DWORD  trunkNb;
        DWORD  timeslotNb;              
    } CG;        
} NMS_GR303_CHANNEL_LOCATION_T;

                    /* Channel Event values */
#define    NMSGR303_EVENT_RX_SUCCESS               0x1
#define    NMSGR303_EVENT_RX_ERROR                 0x2
#define    NMSGR303_EVENT_RX_FIFO_OVERRUN          0x3
#define    NMSGR303_EVENT_RX_ABORT                 0x4
#define    NMSGR303_EVENT_RX_CRC_ERROR             0x5
#define    NMSGR303_EVENT_RX_NON_ALIGNED_OCTET     0x6
#define    NMSGR303_EVENT_RX_BUFFER_OVERFLOW       0x7
#define    NMSGR303_EVENT_TX_ERROR                 0x8
#define    NMSGR303_EVENT_TX_FIFO_UNDERRUN         0x9
#define    NMSGR303_EVENT_TX_FIFO_OVERRUN          0xA
#define    NMSGR303_EVENT_TX_QUEUE_FULL            0xB

typedef void( *NMS_GR303_CHANNEL_CALLBACK_T )(
                            NMS_GR303_INTERFACE_ID_T interfaceId,
                            NMS_GR303_CHANNEL_LOCATION_T channel_loc, 
                            NMS_GR303_CHANNEL_EVENT_T channel_event,
                            void *databuffer, 
                            DWORD datasize);

typedef void( *NMS_GR303_TRACE_CALLBACK_T )(char *tracebuffer, DWORD datasize);

typedef enum _NMS_GR303_RESULT_T
{
    NMSGR303_SUCCESS                   = 0x00,  /* Success                          */
    NMSGR303_INVALID_PARMS             = 0x01,  /* Invalid parameters               */
    NMSGR303_ALREADY_INITIALIZED       = 0x02,  /* Library already initilized       */
    NMSGR303_FAILED_LOAD_LIB           = 0x03,  /* Failed to load library           */ 
    NMSGR303_NO_MEMORY                 = 0x04,  /* Failed to allocate host memory   */
    NMSGR303_INTERNAL_FAILURE          = 0x05,  /* Operation failed.(See log info)  */
    NMSGR303_NOT_INITIALIZED           = 0x06,  /* Library not initialized          */ 
    NMSGR303_INVALID_INTERFACE_ID      = 0x07,  /* Unknown interface id             */ 
    NMSGR303_INVALID_CHANNEL           = 0x08,  /* Invalid channel location         */
    NMSGR303_INVALID_DS1               = 0x09,  /* Invalid DS1 location.            */
    NMSGR303_OUTOFRESOURCE             = 0x0a,  /* No more resources available      */
    NMSGR303_INVALID_STATE             = 0x0b   /* Invalid state for request        */
} NMS_GR303_RESULT_T;

typedef enum _NMS_GR303_TRACEMASK_T
{
    NMSGR303_TRACEMASK_NONE            = 0x00,
    NMSGR303_TRACEMASK_FUNCTIONS       = 0x01,  
    NMSGR303_TRACEMASK_ERRORS          = 0x02,
	NMSGR303_TRACEMASK_RX_BUF          = 0x04,  
    NMSGR303_TRACEMASK_TX_BUF          = 0x08,
	NMSGR303_TRACEMASK_HDLC_ERR        = 0x10,
    NMSGR303_TRACEMASK_ALL             = 0xffff
} NMS_GR303_TRACEMASK_T;

/*============================ Data Structures ============================ */

                       /* DS1 StatusMask values */  
#define NMSGR303_DS1_LOS    0x01  /* Loss of signal                       */
#define NMSGR303_DS1_LOF    0x02  /* Loss of frame                        */
#define NMSGR303_DS1_AIS    0x04  /* Alarm indication signal              */
#define NMSGR303_DS1_RAI    0x08  /* Remote alarm indication              */

                        /* DS1 status structure */
typedef struct {
    DWORD Size;                             /* Size of this structure               */
    NMS_GR303_DS1_STATUSMASK_T StatusMask;  /* Current DS1 status bit mask          */
    DWORD Slips;                            /* Slips                                */
    DWORD Es;                               /* Errors seconds                       */
    DWORD Ses;                              /* Severely errored seconds             */
    DWORD Uas;                              /* Unavailable seconds                  */
    DWORD LineErrors;                       /* Line code violations                 */
    DWORD FrameErrors;                      /* Frame bit errors and CRC errors      */
    DWORD ElaspedTime;                      /* Seconds since counters started       */
} NMS_GR303_DS1_STATUS_T;

                 /* HDLC channel statistics structures */
typedef struct {
    DWORD Octets;                 /* Bytes received count                   */
    DWORD Frames;                 /* Frames received count                  */
    DWORD Drops;                  /* Frames dropped count                   */
    DWORD FifoOverruns;           /* Fifo overrun count                     */
    DWORD Aborts;                 /* Receive abort count                    */
    DWORD CrcErrors;              /* Receive CRC errors count               */
    DWORD NonAlignedOctets;       /* Non-Aligned Octets count               */
    DWORD BufferOverflows;        /* Buffer Overflows count                 */
} CHANNEL_STATISTICS_RECEIVE_T;

typedef struct {
    DWORD Octets;                 /* Bytes transmitted count                */
    DWORD Frames;                 /* Frames transmitted count               */
    DWORD Drops;                  /* Frames dropped count                   */
    DWORD FifoUnderruns;          /* Fifo underrun count                    */
    DWORD FifoOverruns;           /* Fifo overrun count                     */
} CHANNEL_STATISTICS_TRANSMIT_T;

typedef struct {
    DWORD Size;                                 /* Size of this structure   */
    CHANNEL_STATISTICS_RECEIVE_T  chan_stat_rx; /* Receive statistics       */
    CHANNEL_STATISTICS_TRANSMIT_T chan_stat_tx; /* Transmit statistics      */      
} NMS_GR303_CHANNEL_STATISTICS_T;

/*==========================================================================*/
/* Initialize the board family specific library */
NMS_GR303_RESULT_T NMSAPI NMS_GR303Initialize (
                                NMS_GR303_BOARD_FAMILY_T board_family,
                                void *init_parms);
/* Enable/disable tracing */
NMS_GR303_RESULT_T NMSAPI NMS_GR303SetTrace (
                                NMS_GR303_TRACEMASK_T trace_mask, 
                                NMS_GR303_TRACE_CALLBACK_T user_trace_callback,                                
                                void *user_trace_buffer, 
                                DWORD user_trace_buffersize,
                                char *user_file_name);
/* Exit this library */
NMS_GR303_RESULT_T NMSAPI NMS_GR303Exit ();
/* Provision the HDLC channels for the specified interface */
NMS_GR303_RESULT_T NMSAPI NMS_GR303ProvisionInterface (
                                NMS_GR303_INTERFACE_ID_T interfaceId,
                                DWORD num_channels,
                                NMS_GR303_CHANNEL_LOCATION_T *channel_loc_array,
                                NMS_GR303_CHANNEL_CALLBACK_T channel_callback, 
                                void *channel_rx_buffer,
                                DWORD channel_rx_buffersize);
/* Destroy the specified interface. */
NMS_GR303_RESULT_T NMSAPI NMS_GR303DestroyInterface (
                                NMS_GR303_INTERFACE_ID_T interfaceId);
/* Move the specified channel to a different location. */
NMS_GR303_RESULT_T NMSAPI NMS_GR303ModifyChannelLocation (
                                NMS_GR303_INTERFACE_ID_T interfaceId,
                                NMS_GR303_CHANNEL_LOCATION_T *old_channel_loc,
                                NMS_GR303_CHANNEL_LOCATION_T new_channel_loc);
/* Start the physical layer of the provisioned interface. */
NMS_GR303_RESULT_T NMSAPI NMS_GR303StartInterface (
                                NMS_GR303_INTERFACE_ID_T interfaceId);
/* Stop the physical layer of the provisioned interface. */
NMS_GR303_RESULT_T NMSAPI NMS_GR303StopInterface (
                                NMS_GR303_INTERFACE_ID_T interfaceId);
/* Send a LAPD frame to the NMS layer 1 interface */
NMS_GR303_RESULT_T NMSAPI NMS_GR303PhSendData (
                                NMS_GR303_INTERFACE_ID_T interfaceId,
                                NMS_GR303_CHANNEL_LOCATION_T channel_loc,
                                DWORD number_bytes,
                                void *lapd_data);
/* Get statistics for a specified HDLC Channel. */
NMS_GR303_RESULT_T NMSAPI NMS_GR303GetChannelStatistics (
                                NMS_GR303_INTERFACE_ID_T interfaceId,
                                NMS_GR303_CHANNEL_LOCATION_T channel_loc,
                                NMS_GR303_CHANNEL_STATISTICS_T *channel_stat);
/* Reset statistics structure for the specified HDLC channel. */
NMS_GR303_RESULT_T NMSAPI NMS_GR303ResetChannelStatistics (
                                NMS_GR303_INTERFACE_ID_T interfaceId,
                                NMS_GR303_CHANNEL_LOCATION_T channel_loc);
/* Get the status for the specified DS1 link. */
NMS_GR303_RESULT_T NMSAPI NMS_GR303GetDS1Status (
                                NMS_GR303_INTERFACE_ID_T interfaceId, 
                                NMS_GR303_DS1_LOCATION_T ds1_loc,
                                NMS_GR303_DS1_STATUS_T *ds1_status);
/* Reset the status structure for the specified DS1 link. */
NMS_GR303_RESULT_T NMSAPI NMS_GR303ResetDS1Status (
                                NMS_GR303_INTERFACE_ID_T interfaceId, 
                                NMS_GR303_DS1_LOCATION_T ds1_loc);

/*==========================================================================*/
#ifdef __cplusplus
}
#endif
#endif /*_NMS_GR303LIB_H_*/
/*=============================== [eof] ====================================*/
